﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Employee.aspx.cs" Inherits="Meeting.Web.Admin.BaseSet.Employee" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>人员管理</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
    <!--easyui-->
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <!--树样式-->
    <%--  <link rel="stylesheet" href="../../Css/zTreeStyle/zTreeStyle.css" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery.ztree.core-3.5.min.js"></script>--%>
    <script type="text/javascript">
        //$("#dept").attr("disabled", "true");
        $(function () { InitGird(); });
        function InitGird() {
            $('#mainList').datagrid({
                url: 'EmployeeOperation.ashx?method=GetEmployee',
                singleSelect: true,
                collapsible: false,
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20,  //默认一页数据条数
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        OpenWin();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        EditData();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        $.messager.confirm('警告', '该记录将被永久删除，确定吗?', function (e) {
                            if (!e) return;
                            DeleteData();
                        })
                    }
                }]

            });
            //设置分页
            var p = $("#mainList").datagrid("getPager");
            $(p).pagination({
                pageSize: 20, //每页显示的记录条数，默认为10   
                pageList: [10, 20, 30], //可以设置每页记录条数的列表   
                beforePageText: '第', //页数文本框前显示的汉字   
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
            });
        }


        //新增打开窗口
        function OpenWin() {
            //设置默认媒体
            $("#Mode").val("add");
            $("#Account").removeAttr("disabled");
            $("#Account").val('');
            $('#Name').val('');
            $("#Title").val('');
            $("#Mobile").val('');
            $("#Comment").val('');
            //
            $("#edit").dialog("open").dialog('setTitle', '新加人员');
        }
        //保存数据
        function AddData() {
            var account = $("#Account").val();
            var roleId = $("#RoleId").val();
            var roleName = $("#RoleName").val();
            var name = $("#Name").val();
            var title = $("#Title").val();
            var mobile = $("#Mobile").val()
            var comment = $("#Comment").val();

            if (account == "") {
                $.messager.alert('提示', '登录名不能为空！');
                return;
            }
            if (name == "") {
                $.messager.alert('提示', '姓名不能为空！');
                return;
            }
            var postData = { Account: account, Name: name, Title: title, RoleId:roleId, RoleName:roleName, Mobile: mobile, Comment: comment };
            //提交
            $.post("EmployeeOperation.ashx?method=" + $("#Mode").val(), postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '保存成功');
                    $("#mainList").datagrid('reload');
                    $("#edit").dialog("close");
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        }
        //edit
        function EditData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                parent.$.messager.alert("提示", '请选择您要修改的记录！');
                return;
            }
            $("#Mode").val("edit");
            $("#Account").attr("disabled", "true");
            $("#RoleId").val(row.RoleId);
            $("#RoleName").val(row.RoleName);
            //
            $("#Account").val(row.Account);
            $('#Name').val(row.Name);
            $("#Title").val(row.Title);
            $("#Mobile").val(row.Mobile);
            $("#Comment").val(row.Comment);
            //打开窗口
            $('#edit').window('open').dialog("setTitle", "编辑人员信息");
        }
        //delete
        function DeleteData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                $.messager.alert("提示", '请选择您要删除的记录！');
                return;
            }
            var postData = { Account: row.Account };
            $.post("EmployeeOperation.ashx?method=delete", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '删除成功');
                    $("#mainList").datagrid('reload');
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });

        }

        //
        function DoSearch() {
            $('#mainList').datagrid('load', {
                keyword: $("#fname").val()//用户名 
            });
        }


        //打开部门选择窗口
        function OpenRoleWin() {
            $('#roleList').datagrid({
                url: 'EmployeeOperation.ashx?method=GetRole',
                singleSelect: false,
                collapsible: false,
                pagination: false, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20
            });
            $('#tree').window('open').dialog("setTitle", "请选择部门");
        }
        function SelectRole() {
            //
            var rows = $('#roleList').datagrid('getSelections');
            var roleId = "";
            var roleName = "";
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                roleId += row.Id + ";";
                roleName += row.Name + ";";
            }
            if (roleId.length > 0) roleId = roleId.substring(0, roleId.length - 1);
            if (roleName.length > 0) roleName = roleName.substring(0, roleName.length - 1);
            $("#RoleId").val(roleId);
            $("#RoleName").val(roleName);
            $('#tree').dialog('close');
        }
        
                                                                                                 
    </script>
    <style type="text/css">
        .table_edit
        {
            text-align: left;
        }
        .table_edit tr
        {
            height: 32px;
        }
        
        input, textarea
        {
            border: 1px solid #AED0EA;
            padding: 2px;
            height: 16px;
        }
    </style>
</head>
<body>
    <div>
        姓名:
        <input id="fname" style="width: 120px;" class="easyui-validatebox" type="text" /><a
            href="#" class="easyui-linkbutton" onclick="DoSearch();">查询</a>
    </div>
    <div style="min-height: 500px; width: 900px; text-align: left;">
        <table id="mainList" class="easyui-datagrid">
            <thead>
                <tr>
                    <th data-options="field:'Account',width:120">
                        登录账号
                    </th>
                    <th data-options="field:'Name',width:120">
                        真实姓名
                    </th>
                    <th data-options="field:'Mobile',width:120">
                        手机号
                    </th>
                    <th data-options="field:'Title',width:120">
                        职务
                    </th>
                    <th data-options="field:'RoleId',width:120,hidden:true">
                        角色
                    </th>
                    <th data-options="field:'RoleName',width:120">
                        角色
                    </th>
                    <th data-options="field:'Comment',width:120">
                        备注
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="edit" class="easyui-dialog" title="编辑用户" style="width: 400px; height: 300px;"
        closed="true" buttons="#edit-buttons">
        <form id="form_edit" name="form_edit">
        <table class="table_edit" style="text-align: left;">
            <tr>
                <td class="tdName">
                    登录账号:
                    <input id="Mode" type="hidden" />
                </td>
                <td class="tdText">
                    <input id="Account" class="easyui-validatebox" style="width: 160px;" name="name" />
                </td>
            </tr>
            <tr>
                <td class="tdName">
                    真实姓名:
                </td>
                <td class="tdText">
                    <input id="Name" class="easyui-validatebox" style="width: 160px;" name="name" />
                </td>
            </tr>
            <tr>
                <td>
                    角色:
                </td>
                <td>
                    <input type="hidden" id="RoleId" />
                    <input id="RoleName" name="RoleName" style="width: 160px;" class="easyui-validatebox"
                        type="text" /><a href="#" class="easyui-linkbutton" onclick="OpenRoleWin();">选择</a>
                </td>
            </tr>
            <tr>
                <td>
                    职务:
                </td>
                <td>
                    <input id="Title" class="easyui-validatebox" style="width: 160px;" name="province" />
                </td>
            </tr>
            <tr>
                <td>
                    手机号:
                </td>
                <td>
                    <input id="Mobile" class="easyui-validatebox" style="width: 160px;" name="province" />
                </td>
            </tr>
            <tr>
                <td>
                    备 注:
                </td>
                <td>
                    <input id="Comment" class="easyui-validatebox" style="width: 160px;" name="city" />
                </td>
            </tr>
        </table>
        </form>
    </div>
    <div id="edit-buttons">
        <a id="btn_add" href="#" onclick="AddData();" class="easyui-linkbutton">保存</a> <a
            href="#" class="easyui-linkbutton" onclick="$('#edit').dialog('close');return false;">
            取消</a>
    </div>
    <div id="tree" class="easyui-dialog" title="选择角色" style="width: 400px; height: 360px;"
        modal="true" closed="true" buttons="#tree-buttons">
        <form id="formTree" name="formTree">
        <div>
            <table id="roleList" class="easyui-datagrid">
                <thead>
                    <tr>
                        <th data-options="field:'chk',checkbox:true">
                        </th>
                        <th data-options="field:'Id',width:120,hidden:true">
                            Id
                        </th>
                        <th data-options="field:'Name',width:120">
                            角色名称
                        </th>
                    </tr>
                </thead>
            </table>
        </div>
        </form>
    </div>
    <div id="tree-buttons">
        <a id="A1" href="#" onclick="SelectRole();" class="easyui-linkbutton">确定</a> <a href="#"
            class="easyui-linkbutton" onclick="$('#tree').dialog('close');return false;">取消</a>
    </div>
</body>
</html>
